package com.codegeek.project.slope.controller;

import com.codegeek.common.utils.poi.ExcelUtil;
import com.codegeek.framework.aspectj.lang.annotation.Log;
import com.codegeek.framework.aspectj.lang.enums.BusinessType;
import com.codegeek.framework.web.controller.BaseController;
import com.codegeek.framework.web.domain.AjaxResult;
import com.codegeek.framework.web.page.TableDataInfo;
import com.codegeek.project.slope.domain.SlopeGlare;
import com.codegeek.project.slope.service.ISlopeGlareService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 声光报警器Controller
 *
 * @author codegeek
 * @date 2020-02-17
 */
@RestController
@RequestMapping("/slope/glare")
@Api(value = "声光报警器Controller", tags = {"声光报警器操作接口"})
public class SlopeGlareController extends BaseController {
    @Autowired
    private ISlopeGlareService slopeGlareService;

    /**
     * 查询声光报警器列表
     */
    @ApiOperation("查询声光报警器列表")
    @GetMapping("/list")
    public TableDataInfo list(SlopeGlare slopeGlare) {
        startPage();
        List<SlopeGlare> list = slopeGlareService.selectSlopeGlareList(slopeGlare);
        return getDataTable(list);
    }

    /**
     * 导出声光报警器列表
     */
    @ApiOperation("导出声光报警器列表")
    @Log(title = "首页", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SlopeGlare slopeGlare) {
        List<SlopeGlare> list = slopeGlareService.selectSlopeGlareList(slopeGlare);
        ExcelUtil<SlopeGlare> util = new ExcelUtil<SlopeGlare>(SlopeGlare.class);
        return util.exportExcel(list, "glare");
    }

    /**
     * 获取声光报警器详细信息
     */
    @ApiOperation("获取声光报警器详细信息")
    @GetMapping(value = "/getInfo/{glareId}")
    public AjaxResult getInfo(@PathVariable("glareId") Long glareId) {
        return AjaxResult.success(slopeGlareService.selectSlopeGlareById(glareId));
    }

    /**
     * 新增声光报警器
     */
    @ApiOperation("新增声光报警器")
    @Log(title = "首页", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody SlopeGlare slopeGlare) {
        return toAjax(slopeGlareService.insertSlopeGlare(slopeGlare));
    }

    /**
     * 修改声光报警器
     */
    @ApiOperation("修改声光报警器")
    @Log(title = "首页", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody SlopeGlare slopeGlare) {
        return toAjax(slopeGlareService.updateSlopeGlare(slopeGlare));
    }

    /**
     * 删除声光报警器
     */
    @ApiOperation("删除声光报警器")
    @Log(title = "首页", businessType = BusinessType.DELETE)
    @PostMapping("/remove/{glareIds}")
    public AjaxResult remove(@PathVariable Long[] glareIds) {
        return toAjax(slopeGlareService.deleteSlopeGlareByIds(glareIds));
    }
}
